import { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import type { RootState } from '@/types/store'
export function useInitialState<k extends keyof RootState>(
  action: () => void,
  stateName: k
) {
  const dispath = useDispatch()
  // 进入组件就发请求
  useEffect(() => {
    dispath(action())
  }, [dispath, action])
  // 进入组价获取到redux中的数据
  // const state = useSelector(state: Rootstate => state[stateName])

  const state = useSelector((state: RootState) => state[stateName])

  return state
}
